<?php

namespace App\Service\Activity;

use App\Helpers\AliyunUtil;
use App\Model\Act\WishTree;
use App\Model\Gift;
use App\Model\UserProfile;
use App\Service\BaseService;

/**
 * 许愿树 - 我的许愿
 */
class WishTreeMyService extends BaseService
{
    public function handle()
    {
        $userId = $this->userId;
        $list = WishTree::getList(200, $userId);
        $giftIds = array_column($list, 'wish_gift_id');
        // $profiles = UserProfile::getProfile($userId);
        $giftInfo = Gift::getBatchInfo($giftIds);
        $ret['list'] = [];
        foreach ($list as $item) {
            $gift = $giftInfo[$item['wish_gift_id']];
            $ret['list'][] = [
                'gift_name' =>  $gift['name'],
                'coin' => $gift['coin'],
                'num' => $item['num'],
                'gift_icon' => AliyunUtil::imageResize(AliyunUtil::IMG_HOST_V2 . $gift['icon'], 120, 120),
                'wish_time' => date('Y-m-d', strtotime($item['created_at'])),
                'text' => "价值{$item['coin']}金币，已放入背包"
            ];
        }
        return $ret;
    }
}
